<template>
    <div class="order-info">
        <div class="info-message">
            <h2>
                <span>Order ID：</span>
                <strong v-text="info.order_code"></strong>
                <OrderState :info="orderStatus" />
            </h2>

            <!-- 下单时间 -->
            <div class="info-message-text">
                <span>Creation time:</span>
                <strong v-text="$timeFormat(info.created_at)"></strong>
            </div>

            <!-- 订单来源 -->
            <div class="info-message-text">
                <span>Source: </span>
                <StoreIconOrder :item="info.shop" />
            </div>

            <!-- 订单编号 -->
            <div class="info-message-text" v-if="info.third_order_code != ''">
                <span>Integrated platform order ID: </span>
                <strong v-text="' #' + info.third_order_code"></strong>
            </div>

            <!-- 问题订单 -->
            <div class="info-message-error" v-if="info.order_state == 15">
                <svg-icon name="notify2" />
                <strong v-text="remarkQuestion"></strong>
            </div>

            <!-- 支付延迟订单 delayed -->
            <div class="info-message-error" v-if="info.order_state == 2 && orderStatus.order_pay_state == 2">
                <img src="@/assets/images/order/dialog-delayed.png" alt="">
                <strong>We have not received your payment for quite a while. Click <a href="/document/help-center?classify=7&detail=109">here</a> to find out why this happened, or contact us for help.</strong>
            </div>

            <!-- 支付失败 failed -->
            <div class="info-message-error" v-if="info.order_state == 2 && orderStatus.order_pay_state == 20">
                <svg-icon name="notify2" />
                <strong>Order payment failed, please contact customer service for help.</strong>
            </div>

            <!-- 已取消订单 -->
            <div class="info-message-cancel" v-if="info.order_state == 11">
                <img src="@/assets/images/order/dialog-canceled.png" alt="">
                <strong>Cancellation time: {{ cancelTime }}</strong>
            </div>
        </div>

        <div class="info-button">
            <OrderCancel v-if="orderStatus.order_state == 1" :info="info" @update="$emit('update',$event)" />
            <OrderRefund v-if="orderStatus.order_state == 2 && [11,20].indexOf(orderStatus.order_pay_state) < 0" :info="info" @update="$emit('update',$event)" />
            <a href="https://m.me/PodPartnerCo" target="view_window">Contact us</a>
        </div>

    </div>
</template>
<script>
export default {
    name: "OrderInfo",
    props: ["info"],
    data () {
        return {

        };
    },
    computed: {
        remarkQuestion () {
            var str = "";
            var state = this.info.state || {};
            var log_state = state.log_state || [];
            log_state.map((item) => {
                if (item.order_state == 15) {
                    str = item.remark;
                }
            });
            return str;
        },
        orderStatus () {
            return {
                ...this.info.state,
                all_custom_count: this.info.all_custom_count,
            }
        },
        cancelTime () {
            let state = (this.info || {}).state || {}
            let log = state.log_state || [];
            let last = log[log.length - 1] || {};
            return this.$timeFormat(last.state_time);
        }

    },
    methods: {

    },
    created () { },
};
</script>
<style lang="scss" scoped>
.order-info {
    display: flex;
    position: relative;
}

.info-message {
    flex: 1;
    line-height: 30px;

    h2 {
        display: flex;
        font-weight: normal;
        strong,
        span {
            font-size: 28px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            line-height: 32px;
        }
        .order-name {
            height: 28px;
            margin-left: 6px;
        }
    }

    .info-message-text {
        display: flex;
        margin-top: 14px;
        font-size: 14px;
        font-family: Roboto-Regular, Roboto;
        font-weight: 400;
        color: #555555;
        line-height: 18px;

        & + .info-message-text {
            margin-top: 10px;
        }

        span {
            margin-right: 4px;
        }
        strong {
            font-weight: inherit;
        }

        .store-icon-order {
            margin-left: 8px;
            &::v-deep figure {
                width: 18px;
                min-width: 18px;
                height: 18px;
            }
            &::v-deep span {
                color: inherit;
            }
        }
    }

    .info-message-error {
        margin-top: 14px;
        background: #f5ebeb;
        border-radius: 8px;
        border: 1px solid #f0e2e2;
        padding: 10px;
        display: flex;
        align-items: center;
        svg,
        img {
            width: 16px;
            height: 16px;
            margin-right: 4px;
            color: #c62828;
        }
        strong {
            font-size: 14px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #c62828;
            line-height: 16px;
        }
        a {
            color: #087196;
            text-decoration: underline;
            &:hover {
                color: #287e9c;
                text-decoration: none;
            }
        }
    }

    .info-message-cancel {
        margin-top: 14px;
        background: #ebebeb;
        border-radius: 8px;
        border: 1px solid #e3e3e3;
        padding: 10px;
        display: flex;
        align-items: center;
        svg,
        img {
            width: 16px;
            height: 16px;
            margin-right: 4px;
            color: #c62828;
        }
        strong {
            font-size: 14px;
            font-family: Roboto-Medium, Roboto;
            font-weight: 500;
            color: #000000;
            line-height: 16px;
        }
    }
}

.info-button {
    position: absolute;
    right: 0;
    top: 30px;
    display: flex;
    align-items: center;

    a {
        display: inline-flex;
        height: 32px;
        padding: 0 10px;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
        box-sizing: border-box;
        white-space: nowrap;
        background-color: #fff;
        font-family: Roboto-Medium, Roboto;
        font-weight: 500;
        font-size: 14px;
        line-height: 16px;
        transition: all 0.2s;
        align-items: center;
        justify-content: center;
        color: #000;
        margin-left: 6px;
        &:hover {
            color: #ea4c89;
        }
    }
}
</style>
